import os, shutil


# 修改文件名
def renameFile(oldname, newname):
    shutil.copyfile(oldname, newname)


# 列出txt文件
def listTxtFile(filepath):
    if os.path.isfile(filepath) and ".in" == filepath[-3:]:
        oldName = filepath
        newName = oldName[:-4]
        shutil.copyfile(oldName, newName)


# 遍历目录下所有的文件
def listPath(filepath):
    filepath=filepath+"/"
    fileList = os.listdir(filepath)
    IN=1
    OUT=1
    for fi in fileList:
        fi_d = os.path.join(filepath, fi)
        if os.path.isdir(fi_d):
            listPath(fi_d)
        else:
            if os.path.isfile(fi_d) and ".in" == fi_d[-3:]:
                oldName = fi_d
                newName = filepath+str(IN)+".in"
                os.rename(oldName, newName)
                IN = IN + 1
            if os.path.isfile(fi_d) and ".out" == fi_d[-4:]:
                oldName = fi_d
                newName = filepath+str(OUT)+".out"
                os.rename(oldName, newName)
                OUT = OUT + 1
            if os.path.isfile(fi_d) and ".ans" == fi_d[-4:]:
                oldName = fi_d
                newName = filepath+str(OUT)+".out"
                print(newName)
                os.rename(oldName, newName)
                OUT = OUT + 1



if __name__ == "__main__":
    rootdir = input("请输入文件路径:")
    listPath(rootdir)